package com.example.demo.service;

import com.example.demo.model.UserLevel;
import com.example.demo.mapper.UserLevelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserLevelService {
    private final UserLevelMapper userLevelMapper;

    @Autowired
    public UserLevelService(UserLevelMapper userLevelMapper) {
        this.userLevelMapper = userLevelMapper;
    }

    public UserLevel getUserLevelById(Long userId) {
        return userLevelMapper.selectUserLevelByUserId(userId);
    }

    public void createUserLevel(Long userId, int level, int experience) {
        userLevelMapper.insertUserLevel(userId, level, experience);
    }

    public void updateUserLevel(Long userId, int level, int experience) {
        userLevelMapper.updateUserLevel(userId, level, experience);
    }

    public void deleteUserLevel(Long userId) {
        userLevelMapper.deleteUserLevel(userId);
    }

    public void addExperience(Long userId, int experience) {
        userLevelMapper.addExperience(userId, experience);
    }

    public void levelUp(Long userId) {
        userLevelMapper.levelUp(userId);
    }

    public void levelDown(Long userId) {
        userLevelMapper.levelDown(userId);
    }

    public void addFilesize(Long userId, int filesize) {
        userLevelMapper.addFilesize(userId, filesize);
    }

    public List<UserLevel> getUsersWithFilesizeGreaterThanLevel() {
        return userLevelMapper.selectByFilesizeGreaterThanLevel();
    }
}
